package com.dengqi.mymodule;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;

import com.dengqi.mymodule.activity.arouter.ARouterActivity;
import com.dengqi.mymodule.activity.asynctask.AsyncTaskActivity;
import com.dengqi.mymodule.activity.camera.CameraActivity;
import com.dengqi.mymodule.activity.chenj.ChenJActivity;
import com.dengqi.mymodule.activity.dialog.DialogActivity;
import com.dengqi.mymodule.activity.drawerlayout.DrawerActivity;
import com.dengqi.mymodule.activity.effect.EffectActivity;
import com.dengqi.mymodule.activity.empty.GloadingActivity;
import com.dengqi.mymodule.activity.glide.activity.GlideActivity;
import com.dengqi.mymodule.activity.guide.GuideActivity;
import com.dengqi.mymodule.activity.html.HtmlActivity;
import com.dengqi.mymodule.activity.indicator.IndicatorActivity;
import com.dengqi.mymodule.activity.jsoup.JSoupActivity;
import com.dengqi.mymodule.activity.layoutinflater.LayoutInflaterActivity;
import com.dengqi.mymodule.activity.loader.LoaderActivity;
import com.dengqi.mymodule.activity.memory.MemoryActivity;
import com.dengqi.mymodule.activity.network.NetWorkActivity;
import com.dengqi.mymodule.activity.notch.NotchActivity;
import com.dengqi.mymodule.activity.permission.PermissionActivity;
import com.dengqi.mymodule.activity.popupwindow.PopActivity;
import com.dengqi.mymodule.activity.rxandroid.RxAndroidActivity;
import com.dengqi.mymodule.activity.softinput.SoftInputActivity;
import com.dengqi.mymodule.activity.swipe.SwipeActivity;
import com.dengqi.mymodule.activity.swipedel.SwipeDelActivity;
import com.dengqi.mymodule.activity.touch.TouchActivity;
import com.dengqi.mymodule.activity.umeng.UmengActivity;
import com.dengqi.mymodule.activity.unittest.UnitTestActivity;
import com.dengqi.mymodule.activity.update.UpdateActivity;
import com.dengqi.mymodule.tools.AppManager;

import androidx.appcompat.widget.Toolbar;

public class MainActivity extends BaseActivity {

    long exitTime = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.setTitle("首页");
        initTranScreen();

    }

    private void initTranScreen() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //5.0以上的沉浸式
            //让应用主题内容占用系统状态栏的空间,注意:下面两个参数必须一起使用 stable 牢固的
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            //设置状态栏颜色为透明
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //4.4以上的沉浸式
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }


    public void onBtn1(View view) {
        startActivity(new Intent(this, DrawerActivity.class));
    }

    public void onBtn2(View view) {
        startActivity(new Intent(this, ChenJActivity.class));
    }

    public void onBtn3(View view) {
        startActivity(new Intent(this, UpdateActivity.class));
    }

    public void onBtn4(View view) {
        startActivity(new Intent(this, PermissionActivity.class));
    }

    public void onBtn5(View view) {
        startActivity(new Intent(this, GuideActivity.class));
    }

    public void onBtn6(View view) {
        startActivity(new Intent(this, GlideActivity.class));
    }

    public void onBtn7(View view) {
        startActivity(new Intent(this, CameraActivity.class));
    }

    public void onBtn8(View view) {
        startActivity(new Intent(this, MemoryActivity.class));
    }

    public void onBtn9(View view) {
        startActivity(new Intent(this, CameraActivity.class));
    }

    public void onBtn10(View view) {
        startActivity(new Intent(this, DialogActivity.class));
    }

    public void onBtn11(View view) {
        startActivity(new Intent(this, PopActivity.class));
    }

    public void onBtn12(View view) {
        startActivity(new Intent(this, SwipeDelActivity.class));
    }

    public void onBtn13(View view) {
        startActivity(new Intent(this, SwipeActivity.class));
    }

    public void onBtn14(View view) {
        startActivity(new Intent(this, com.dengqi.mymodule.activity.fragment.FragmentActivity.class));
    }

    public void onBtn15(View view) {
        startActivity(new Intent(this, SoftInputActivity.class));
    }

    public void onBtn16(View view) {
        startActivity(new Intent(this, NotchActivity.class));
    }

    public void onBtn17(View view) {
        startActivity(new Intent(this, LayoutInflaterActivity.class));
    }

    public void onBtn18(View view) {
        startActivity(new Intent(this, UnitTestActivity.class).putExtra("test", "hello"));
    }

    public void onBtn19(View view) {
        startActivity(new Intent(this, ARouterActivity.class));
    }

    public void onBtn20(View view) {
        startActivity(new Intent(this, HtmlActivity.class));
    }

    public void onBtn21(View view) {
        startActivity(new Intent(this, TouchActivity.class));
    }

    public void onBtn22(View view) {
        startActivity(new Intent(this, GloadingActivity.class));
    }

    public void onBtn23(View view) {
        startActivity(new Intent(this, AsyncTaskActivity.class));
    }

    public void onBtn24(View view) {
        startActivity(new Intent(this, LoaderActivity.class));
    }

    public void onBtn25(View view) {
        startActivity(new Intent(this, RxAndroidActivity.class));
    }

    public void onBtn26(View view) {
        startActivity(new Intent(this, UmengActivity.class));
    }


    public void onBtn27(View view) {
        startActivity(new Intent(this, NetWorkActivity.class));
    }

    public void onBtn28(View view) {
        startActivity(new Intent(this, IndicatorActivity.class));
    }
    public void onBtn29(View view) {
        startActivity(new Intent(this, JSoupActivity.class));
    }
    public void onBtn30(View view) {
        startActivity(new Intent(this, EffectActivity.class));
    }



    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) { //拦截/屏蔽返回键
            long currentTime = System.currentTimeMillis();
            if (currentTime - exitTime > 2000) {
                Toast.makeText(MainActivity.this, "再按一次退出", Toast.LENGTH_SHORT).show();
                exitTime = currentTime;
            } else {
                /**
                 * 全部退出
                 */
                AppManager.finishAllActivity();
                /**
                 * 返回桌面,应用并没有退出
                 */
//                Intent intent = new Intent(Intent.ACTION_MAIN);
//                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                intent.addCategory(Intent.CATEGORY_HOME);
//                startActivity(intent);
            }

            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

}
